<template>
	<view style="padding: 20px;">
		<button @click="onsetTimeCall()">单次定时器setTimerout</button>
		<button @click="onsetTimeCallxy(userName,password)">带参数setTimerout</button>
		<button @click="onsetTimeClear()"  plain type="warn">取消定时器</button>
		<button @click="onInteral()"  plain type="primary">周期打印</button>
		<button @click="onclearInteral()" plain type="primary">取消周期打印</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:"xmy",
				password:'12345',
				timeId:null,
				interalId:null,
				count:1
				
			}
		},
		methods: {
			onsetTimeCall() {
				console.log("onsetTimeout--->");
				// setTimeout(callback,ms,any[])
				this.timeId=setTimeout(()=>{
					console.log("我延迟2秒");
				},2000)
			},
			onsetTimeCallxy(name,pwd) {
				console.log("name: ",this.userName);
				console.log("password: ",this.password);
				setTimeout((x,y)=> {
					console.log("name:"+x+"pwd"+y);
				},2000,name,pwd)
			},
			onsetTimeClear() {
				console.log("取消定时器："+this.timeId);
				clearTimeout(this.timeId)
			},
			onInteral(){
				this.interalId=setInterval(()=> {
					this.count++;
					console.log("周期打印",this.count);
				},1000)
			},
			onclearInteral() {
				console.log("取消周期打印",this.interalId);
				clearInterval((this.interalId))
			}
			
		}
	}
</script>

<style>
button {
	margin: 10px;
}
</style>
